package ui.magic.magicui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import ui.magic.magiclibs.container.Absolute.AbsoluteMagicUi;
import ui.magic.magiclibs.container.Absolute.FVector;
import ui.magic.magiclibs.container.Linear.LinearMagicNull;
import ui.magic.magiclibs.container.Linear.LinearMagicUi;
import ui.magic.magiclibs.container.LittleThings.RoundButton;
import ui.magic.magiclibs.container.LittleThings.SlideSlipItem;
import ui.magic.magiclibs.container.View.TopBar;
import ui.magic.magiclibs.container.View.UnderBar;

public class TestActivity extends AppCompatActivity implements View.OnClickListener{

    private LinearMagicUi magicUi;
    private Button btn3;
    private boolean b=false;
    private Button btn2;
    private TopBar topBar;
    private UnderBar underBar;
    private AbsoluteMagicUi absoluteMagicUi;
    private FVector start=new FVector();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        magicUi=(LinearMagicUi)findViewById(R.id.magic_ui);
        magicUi.setVertical();
        init();
    }

    public void init(){
        Bitmap bitmap2=BitmapFactory.decodeResource(getResources(),R.drawable.bg2);
        RoundButton image=new RoundButton(magicUi.getContext());
        image.setBackgroundImage(bitmap2);
        image.setText("图片背景");
        image.setTextColor(Color.RED);
        image.setCircle(true);
        btn2=new Button(magicUi.getContext());
        btn2.setText("test2");
        btn2.setOnClickListener(this);
        topBar=new TopBar(magicUi.getContext());
        topBar.setTitle("标题");
        underBar=new UnderBar(magicUi.getContext());
        Button menu1=new Button(underBar.getContext());
        menu1.setText("Frame");
        menu1.setOnClickListener(this);
        Button menu2=new Button(underBar.getContext());
        menu2.setText("Absolute");
        menu2.setOnClickListener(this);
        Button menu3=new Button(underBar.getContext());
        menu3.setText("Mulitply");
        menu3.setOnClickListener(this);
        underBar.addViewMenu(menu1);
        underBar.addViewMenu(menu2);
        underBar.addViewMenu(menu3);
        magicUi.setAlign(LinearMagicUi.TOP|LinearMagicUi.CENTER);
        magicUi.addChild(topBar,100,8);
        magicUi.addChild(image,40,20);
        magicUi.addChild(btn2,40,20);
        absoluteMagicUi=new AbsoluteMagicUi(magicUi.getContext());
        btn3=new Button(absoluteMagicUi.getContext());
        btn3.setTextColor(Color.BLACK);
        btn3.setText("btn3");
        absoluteMagicUi.setSelfInit();
        absoluteMagicUi.setBackgroundColor(Color.BLUE);
        absoluteMagicUi.addChild(btn3,20,10,30,80);
        start.x=20;
        start.y=10;
        magicUi.addChild(absoluteMagicUi,80,20);
        magicUi.addSplitBar(100,22);
        magicUi.addChild(underBar,100,8);
       }

    @Override
    public void onClick(View v) {
        Intent intent;
        if(v==underBar.getMenuView(1)){
            intent=new Intent(TestActivity.this, FrameActivity.class);
            TestActivity.this.startActivity(intent);
        }else if(v==underBar.getMenuView(2)){
            intent=new Intent(TestActivity.this,AbsoluteActivity.class);
            TestActivity.this.startActivity(intent);
        }else if(v==underBar.getMenuView(3)){
            intent=new Intent(TestActivity.this,MulActivity.class);
            TestActivity.this.startActivity(intent);
        } else{
            if(b){
                b=false;
                start.x-=5;
            }else{
                b=true;
                start.x+=5;
            }
            absoluteMagicUi.changeChildLocation(btn3,start.x,start.y);
            magicUi.changeChildSize(absoluteMagicUi,60,20);
        }

    }
}
